package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * @description: 动态条件查询购物车数据
     * @author: zhouzhijie
     * @date: 2023/11/22 9:42
     * @param: [shoppingCart]
     * @return:
     **/
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * @description: 根据id来修改商品数量
     * @author: zhouzhijie
     * @date: 2023/11/22 10:00
     * @param: [cart]
     * @return:
     **/
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * @description: 插入购物车数据
     * @author: zhouzhijie
     * @date: 2023/11/22 10:26
     * @param: [shoppingCart]
     * @return:
     **/
    @Insert("insert into shopping_cart " +
            "(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * @description: 根据用户id删除购物车数据 (清空当前用户的购物车)
     * @author: zhouzhijie
     * @date: 2023/11/22 16:07
     * @param: [useId]
     * @return: 
     **/
    @Delete("delete from shopping_cart where user_id = #{uesrId}")
    void deleteByUserId(Long userId);

    /**
     * @description: 动态条件删除购物车商品数据
     * @author: zhouzhijie
     * @date: 2023/11/22 16:54
     * @param: [shoppingCart]
     * @return:
     **/
    void delete(ShoppingCart shoppingCart);

    /**
     * @description: 批量插入购物车数据
     * @author: zhouzhijie
     * @date: 2023/11/25 23:36
     * @param: [shoppingCartList]
     * @return: 
     **/
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
